package com.android.presenter.info;

import com.android.model.net.HttpObserver;
import com.android.presenter.base.BasePresenter;
import com.android.model.info.UserModel;
import com.android.model.entity.res.UserInfoResult;
import com.android.presenter.iview.IUserInfoView;
import com.android.util.log.LogUtil;

/**
 * author:  TenFace
 * date:    2017/9/27
 * description: 查询用户信息
 */

public class QueryUserInfoPresenter extends BasePresenter<IUserInfoView> {

    private static final String TAG = QueryUserInfoPresenter.class.getSimpleName();
    private UserModel mUserModel;

    public QueryUserInfoPresenter(IUserInfoView iUserInfoView) {
        super(iUserInfoView);
        mUserModel = UserModel.getInstance();
    }

    public void getUserInfo(String token) {
        mUserModel.getUserInfo(token, new HttpObserver<UserInfoResult>() {
            @Override
            public void onSuccess(UserInfoResult userInfoResult) {
                LogUtil.e(TAG, "查询用户信息成功");
                if (mIView != null) {
                    mIView.queryUserInfoSuccess(userInfoResult);
                }
            }

            @Override
            public void onError(int errType, String errMessage) {
                LogUtil.e(TAG, "失败码：" + errType + "》》信息：" + errMessage);
                if (mIView != null) {
                    mIView.queryUserInfoFail(errType, errMessage);
                }
            }
        }, mIView.getLifeSubject());
    }

}
